package com.yxjx.duoxue.comment;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.TextView;

public class ExpandableTextView extends TextView {

	public ExpandableTextView(Context context, AttributeSet attrs) {
		super(context, attrs);
		reset();
		setOnClickListener(mClickListener);
	}

	boolean isExpanded = false;
	boolean mExpandable = true;
	int maxMaxLines = 2000;
	int minMaxLines = 3;
	
	private View.OnClickListener mClickListener = new View.OnClickListener() {
		
		@Override
		public void onClick(View arg0) {
			isExpanded = !isExpanded;
			setMaxLines(isExpanded ? maxMaxLines : minMaxLines);
		}
	};
	
	// used when re-use item comment record.
	public void reset() {
		isExpanded = false;
		setMaxLines(isExpanded ? maxMaxLines : minMaxLines);
	}
	
	public void setExpandable(boolean expandable) {
		mExpandable = expandable;
		if (mExpandable) {
			setOnClickListener(mClickListener);
		} else {
			setOnClickListener(null);
		}
	}

}
